package org.isource.admin;

import java.io.IOException;

import javax.jdo.PersistenceManager;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.isource.common.PMF;
import org.isource.pojo.ThirdParty;

@SuppressWarnings("serial")
public class AddThirdParty extends HttpServlet {

	@Override
	public void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws IOException {
		String name = req.getParameter("name");
		String version = req.getParameter("version");
		String category = req.getParameter("category");

		ThirdParty tp = new ThirdParty(name, version, category);
		doPostJDO(tp);
		
		resp.sendRedirect("/admin");
	}

	private void doPostJDO(ThirdParty tp) {
		PersistenceManager pm = PMF.get().getPersistenceManager();
		try {
			pm.makePersistent(tp);
		} finally {
			pm.close();
		}
	}
}
